import json

# json的学习

# json与Python类型的转换
str = '{"name": "张三"}'
obj = json.loads(str)
print(f"{type(obj)} : {obj}")
# ensure_ascii=False 不使用ascii
dumps = json.dumps(obj, ensure_ascii=False)
print(f"{type(dumps)} : {dumps}")

# json保存到文件与读取
json.dump(obj, open("name.txt", "w", encoding="utf-8"), ensure_ascii=False)

load_str = json.load(open("name.txt",encoding="utf-8"))
print(load_str)
